package com.du.dumall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.du.dumall.product.vo.AttrVo;
import com.du.dumall.product.vo.PageAttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.du.dumall.product.entity.AttrEntity;
import com.du.dumall.product.service.AttrService;
import com.du.dumall.common.utils.PageUtils;
import com.du.dumall.common.utils.R;

import javax.annotation.Resource;


/**
 * 商品属性
 *
 * @author dupeng
 * @email 13576245006@163.com
 * @date 2021-12-20 17:10:04
 */
@RestController
@RequestMapping("/product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

//    @Autowired
//    private MemberFeignService memberFeignService;

//    @RequestMapping("/member")
//    public R memberInfo(){
////        R info = memberFeignService.info(1L);
//        return R.ok().put("use",info);
//    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);
        return R.ok().put("page", page);
    }

    @GetMapping("/{attrType}/list/{catId}")
    public R baseList(@RequestParam Map<String, Object> params,
                      @PathVariable("catId") Long catId,
                      @PathVariable("attrType") String attrType){
        PageUtils page = attrService.queryBasePage(params,catId,attrType);
        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		PageAttrVo attr = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
